package web;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(filterName = "MyFilter")
public class MyFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
               HttpServletRequest request=(HttpServletRequest)req;
               HttpServletResponse  response=(HttpServletResponse)resp;
            HttpSession  session=request.getSession();//在登录成功后将信息放到了session里，所以取出来
           Object user2 = session.getAttribute("User2");
           if(user2==null){
               request.getRequestDispatcher("/index.jsp").forward(request,response);

           }else{
               chain.doFilter(req,resp);

           }


    }



}
